#ifndef LIVING_ENTITY_H_
#define LIVING_ENTITY_H_

#include <map>
#include <string>
#include <iostream>
#include <fstream>

#include "BornedNumber.h"
#include "Entity.h"

/*!
	The LivingEntity class provides life and attributes support for Entities. The life support is automatically imbedded but the attributes can be fully customized.
	Notes: The way to store the attributes may have to be redesigned a little since it only allows to have a string mapped to a BornedNumber<double>.
*/
class LivingEntity: virtual public Entity
{
	protected:
	BornedNumber<float> life__;					/**< The life of the Entity. */
	std::map<std::string, BornedNumber<double> > attributes__;	/**< The attributes of the Entity. */
	bool underAttack__ ; /**< turns true if the entity is under attack */ 
    float timeCounter__ ; /**< useful for animation sync and other stuffs */

	public:
	/*! Constructor. Initializes the attribute list with attr, the the life informations. Note that the 'default attributes' given in the second constructor are not set here. TODO: a static map with true default values, such as attack rate, dodge, and so. */
	LivingEntity(const std::map<std::string, BornedNumber<double> >& attr, int life=100, int min=0, int max=100);
	/*! Constructor. Initializes with default values. Attributes are also initialized with 0 <= "speed" <= 400 and 0 <= "rotatespeed" <= 180. These values are needed for the PlayerEntity (that is the only reason for these values). */
	LivingEntity(int life=100, int min=0, int max=100);
	/*! Destructor. Nothing needs to be done here. */
	virtual ~LivingEntity();
	
	BornedNumber<float> getLife();

	/*! returns true if life == min life allowed. */
	bool isDead();
	/*! returns true if life > min life allowed. */
	bool isAlive();
	
    /*! returns true if life is under a certain level */
	bool isLifeCritical();
	
	/*! return true if the entity is under attack */
	bool isUnderAttack();
	
	/*! change the under attack status */
	void setUnderAttack(bool status);

	/*! Adds val to the current life. Life will not exceed its max or min value. val can be negative. */
	bool addLife(float val);
	/*! Removes val to the current live. Life will not exceed its max or min value. val can be positive. */
	bool removeLife(float val);

	/*! Checks the existance of an attribute. Returns true if attrName is an existing attribute. */
	bool attributeExists(const std::string& attrName);
	/*! Checks the existance of an attribute. Returns true if attrName is an existing attribute. */
	bool attributeExists(const irr::core::string<c8>& attrName);
	/*! Returns the value of an attribute given its name. TODO: test with a non-existing attribute. */
	BornedNumber<double>& getAttribute(const std::string& attrName);
	/*! Returns the value of an attribute given its name. TODO: test with a non-existing attribute. */
	BornedNumber<double>& getAttribute(const irr::core::string<c8>& attrName);

	/*! Returns the whole map containing all the attributes. Use it well. */
	std::map<std::string, BornedNumber<double> >& getAttributes();

	/*! Loads attributes from file "./baseq3/behaviours/" + entity_type + ".attr" */
	void loadAttributesFromFile(const std::string& entity_type);
};

#endif

